package com.gdiss.www.controller;


import com.gdiss.www.service.CmsContentService;
import com.gdiss.www.vo.ResultVo;
import com.gdiss.www.vo.request.CmsContentRequest;
import com.gdiss.www.vo.response.ListCmsContentResponse;
import com.gdiss.www.vo.response.ShowCmsContentResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yly
 * @since 2021-11-30
 */
@RestController
@RequestMapping("/cms-content")
public class CmsContentController {
    @Autowired
    private CmsContentService cmsContentService;

    @PostMapping("/addContent")
    ResultVo<? super ShowCmsContentResponse> insertContent(
            @RequestBody @Valid CmsContentRequest contentRequest){
        return cmsContentService.insertCmsContent(contentRequest);
    }

    @GetMapping("/content/{contentId}")
    ResultVo<? super ShowCmsContentResponse> queryCmsContent(
            @PathVariable int contentId){
        return cmsContentService.queryCmsContent(contentId);
    }

    @GetMapping("/content/{curr}/{size}/{categoryId}")
    ResultVo<? super ListCmsContentResponse> queryCmsContentByCategory(
            @PathVariable int curr,
            @PathVariable int size,
            @PathVariable int categoryId){
        return cmsContentService.queryCmsContentByCategory(curr,size,categoryId);
    }

    @GetMapping("/content/search/{curr}/{size}/{search}")
    ResultVo<? super ListCmsContentResponse> queryCmsContentBySearch(
            @PathVariable int curr,
            @PathVariable int size,
            @PathVariable String search){
        return cmsContentService.queryCmsContentBySearch(curr,size,search);
    }
}

